package com.common.component.log;//package com.amz.common.component;
//
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Enumeration;
//
///**
// * @author lying
// * @version 1.0
// * @ClassName LogAspect
// * @date 2021/10/28 11:20
// */
//
//@Aspect
//@Component
//@Slf4j
//public class LogAspect {
//
//    @Pointcut("execution(public * com.amz..controller.*.*(..))")
//    public void log() {
//
//    }
//
//
//    /**
//     * 前置通知
//     *
//     * @param joinPoint
//     */
//    @Before("log()")//log()方法之前
//    public void doBefore(JoinPoint joinPoint) {
//        //接收请求，记录请求
//        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = sra.getRequest();
//        Enumeration<String> names = request.getHeaderNames();
//        StringBuilder headers = new StringBuilder();
//        headers.append("[");
//        while (names.hasMoreElements()) {
//            String name = names.nextElement();
//            headers.append(name).append(":").append(request.getHeader(name)).append(",");
//        }
//        headers.append("]");
//        //记录日志
//        log.info(String.format("{method:%s<-->url:%s<-->ip:%s<-->headers:%s}",  request.getMethod(),request.getRequestURI(),
//        request.getRemoteAddr(),headers));
//    }
//
////    /**
////     * 后置通知
////     * @param ret
////     */
////    @AfterReturning(returning = "ret", pointcut = " log() ")
////    public void doAfter(Object ret) {
////        log.info("response" + ret);//处理完成，返回
////    }
//}
